// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import ipPort from "../../common/ipPort";
import { get, post } from "../../utils/requestUtil"

export async function addFavour(value){
    try {
        let res = await post(ipPort + '/api/default/addFavour', value);
        if (res.data.success) {
            return { success: true, msg: '点赞成功', favour: res.data.favour }
        } else {
            return { success: false, msg: '点赞失败' }
        }
    } catch (error) {
        return { success: false, msg: error }
    }
}

export async function getComments(value){
    try {
        let res = await get(ipPort + '/api/default/getComments', value);
        if (res.success) {
            return { success: true, msg: '', comments: res.comments }
        } else {
            return { success: false, msg: '', comments: [] }
        }
    } catch (error) {
        return { success: false, msg: error }
    }
}

export async function comment(value){
    try {
        let res = await post(ipPort + '/api/default/comment', value);
        if (res.data.success) {
            return { success: true, msg: '评论成功', comments: res.data.comments }
        } else {
            return { success: false, msg: '评论失败' }
        }
    } catch (error) {
        return { success: false, msg: error }
    }
}

export async function reply(value){
    try {
        let res = await post(ipPort + '/api/default/reply', value);
        if (res.data.success) {
            return { success: true, msg: '回复成功', comments: res.data.comments }
        } else {
            return { success: false, msg: '回复失败' }
        }
    } catch (error) {
        return { success: false, msg: error }
    }
}